package com.cy.pj.sys.controller;

import com.cy.pj.sys.controller.pojo.jsonResult;
import com.cy.pj.sys.pojo.SysLog;
import com.cy.pj.sys.service.SysLogService;
import com.cy.pj.sys.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sysLog/")
public class SysLogController {
    @Autowired
    private SysLogService sysLogService;


    @GetMapping

     public jsonResult selectLogs(SysLog sysLog){
        //分页

        //List<SysLog> list = sysLogService.selectLogs(sysLog);
        //return new jsonResult(list);
        return  new jsonResult(
                PageUtil.startPage().doSelectPageInfo(
                        ()->
                        {
                            String proxyCls = sysLogService.getClass().getName();
                            System.out.println("proxyCls="+proxyCls);
                            sysLogService.selectLogs(sysLog)  ;
                        }

                )
        );
     }

     @GetMapping("{id}")
     public jsonResult selectById(@PathVariable Long id){
         SysLog sysLog = sysLogService.selectById(id);
         String proxyCls = sysLogService.getClass().getName();
         System.out.println("proxyCls="+proxyCls);
         return new jsonResult(sysLog);

     }

     @PostMapping
     public jsonResult insertLog(@RequestBody SysLog sysLog){
         sysLogService.insertLog(sysLog);
        return new jsonResult("insertLog ok");
     }

     @DeleteMapping("{ids}")
     public jsonResult deleteById(@PathVariable Long...ids){
         int i = sysLogService.deleteById(ids);
        return new jsonResult(i,i==1?"deleteById ok":"ServiceException deleteById No");
     }
}
